{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 align='center' style='color:purple'>Clustering With K Means - Python Tutorial</h1>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "      <th>Income($)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Rob</td>\n",
       "      <td>27</td>\n",
       "      <td>70000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Michael</td>\n",
       "      <td>29</td>\n",
       "      <td>90000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mohan</td>\n",
       "      <td>29</td>\n",
       "      <td>61000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ismail</td>\n",
       "      <td>28</td>\n",
       "      <td>60000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Kory</td>\n",
       "      <td>42</td>\n",
       "      <td>150000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name  Age  Income($)\n",
       "0      Rob   27      70000\n",
       "1  Michael   29      90000\n",
       "2    Mohan   29      61000\n",
       "3   Ismail   28      60000\n",
       "4     Kory   42     150000"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"income.csv\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x159c7655ac8>"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEKCAYAAADEovgeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHvlJREFUeJzt3X+wVOWd5/H3Z8Af10kUEMaBiw4kIil/TQg3xIxJ1miW\ny2ZSgXUYQyoZmR1WKtFKMpsZMjCZiplYKXHYjBtnVrec6IomqxLHIJVoCJH82E0N4CVoEJRwE2Lk\nioIimh+MAfLdP87T0rT3Xm5Dnz6n+35eVV339HPOc/p7urr48vw4z1FEYGZmlqffKToAMzNrf042\nZmaWOycbMzPLnZONmZnlzsnGzMxy52RjZma5c7IxM7PcOdmYmVnunGzMzCx3I4sOoCzGjh0bkyZN\nKjoMM7OWsnHjxucjYtzRjnOySSZNmkRPT0/RYZiZtRRJTw3lOHejmZlZ7pxszMwsd042ZmaWOycb\nMzPLnZONmZnlzrPRzKx0Vm7qY9nqbTyzbz8TRnWwqHsqc6Z1Fh2WHQcnGzMrlZWb+lhy/2b2HzgE\nQN++/Sy5fzOAE04LczeamZXKstXbXk00FfsPHGLZ6m0FRWSNkFuykXS7pN2SHq8p/5ikJyVtkfQP\nVeVLJPVK2iapu6p8uqTNad9NkpTKT5J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7iOzZQQ8D24Fvky2qekTM6f17yWbd/aQEMfeS9b1Xvvv/VYbveZB47wI2p/JV\nwPiyf8dl/i1XxXIJh2d2lfZ3PEjMpfwdR4RXEDAzs/y5G83MzHLnZGNmZrlzsjEzs9w52ZiZWe6c\nbMzMLHdONmYlIGmOpJD0pqJjMcuDk41ZOXwQ+H/pr1nbcbIxK1haD+8dwAKyu8GR9DuSbk7PJlkj\n6UFJc9O+6ZK+lxZRXF2zmoBZKTnZmBVvNvDNiPgx8IKk6WTrh00CzgX+DHg7vLp+3j8BcyNiOnA7\n8Pkigjarx8iiAzAzPgh8MW3fk96PBL4a2UKbz0r6Tto/FTgfWJMtp8cIslWfzUrNycasQJLGAJcC\nF0gKsuQRZCvx9lsF2BIRb29SiGYN4W40s2LNBe6KiD+IiEkRcSawA9gL/EkauzmDbLFFgG3AOEmv\ndqtJOq+IwM3q4WRjVqwP8tpWzL8Cv0/21MetwJeBHwIvRfbo4bnADZIeI1vZ94+aF67ZsfGqz2Yl\nJel1EfFLSacDG4CLI+LZouMyOxYeszErr6+nh5CdCFznRGOtzC0bMzPLncdszMwsd042ZmaWOycb\nMzPLnZONmZnlzsnGzMxy52RjZma5+//OoqnYVd1B+gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x159c7609748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(df.Age,df['Income($)'])\n",
    "plt.xlabel('Age')\n",
    "plt.ylabel('Income($)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0])"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "km = KMeans(n_clusters=3)\n",
    "y_predicted = km.fit_predict(df[['Age','Income($)']])\n",
    "y_predicted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "      <th>Income($)</th>\n",
       "      <th>cluster</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Rob</td>\n",
       "      <td>27</td>\n",
       "      <td>70000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Michael</td>\n",
       "      <td>29</td>\n",
       "      <td>90000</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mohan</td>\n",
       "      <td>29</td>\n",
       "      <td>61000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ismail</td>\n",
       "      <td>28</td>\n",
       "      <td>60000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Kory</td>\n",
       "      <td>42</td>\n",
       "      <td>150000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name  Age  Income($)  cluster\n",
       "0      Rob   27      70000        2\n",
       "1  Michael   29      90000        2\n",
       "2    Mohan   29      61000        0\n",
       "3   Ismail   28      60000        0\n",
       "4     Kory   42     150000        1"
      ]
     },
     "execution_count": 200,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['cluster']=y_predicted\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  3.29090909e+01,   5.61363636e+04],\n",
       "       [  3.82857143e+01,   1.50000000e+05],\n",
       "       [  3.40000000e+01,   8.05000000e+04]])"
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "km.cluster_centers_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x159c7836128>"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEKCAYAAADEovgeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYVdWZ7/HvW1ACBVoIEhrBqiKRYBhEpSAOQcEBMYlK\nFCNaRuzYVqc16eTaba4+lRunB6OdtBrHXDp6HSgHFEVMa9I4tcZcFXBiUAa1CiGoJRhAuaVAvfeP\nvao8dajhAGefqX6f5zlP7bP2XrvefTzWy1p77bXM3REREYlTUbYDEBGRwqdkIyIisVOyERGR2CnZ\niIhI7JRsREQkdko2IiISOyUbERGJnZKNiIjETslGRERi1z3bAeSK/fbbzysqKrIdhohIXlm8ePHH\n7j6gs+OUbIKKigoWLVqU7TBERPKKmdWncpy60UREJHZKNiIiEjslGxERiZ3u2XRg27ZtrF27lsbG\nxmyHUlB69uzJkCFDKC4uznYoIpIhSjYdWLt2LXvvvTcVFRWYWbbDKQjuzoYNG1i7di1Dhw7Ndjgi\nkiHqRutAY2Mj/fv3V6JJIzOjf//+ai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r7uXu3uFux8AvAdsBE4P\n924GEk22CLACGGBmLd1qZjYyG4GL7AolG5HsOoudWzFzgb8jWvVxOTAbeBXY5NHSw9OA68zsDaKZ\nfY/MXLgiu0ezPovkKDPr4+6fmll/4BXgKHf/INtxiewO3bMRyV1/CIuQ7QVcrUQj+UwtGxERiZ3u\n2YiISOyUbEREJHZKNiIiEjslGxERiZ2SjYiIxE7JRkREYvf/AT3pejZO63l3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x159c7484a90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df1 = df[df.cluster==0]\n",
    "df2 = df[df.cluster==1]\n",
    "df3 = df[df.cluster==2]\n",
    "plt.scatter(df1.Age,df1['Income($)'],color='green')\n",
    "plt.scatter(df2.Age,df2['Income($)'],color='red')\n",
    "plt.scatter(df3.Age,df3['Income($)'],color='black')\n",
    "plt.scatter(km.cluster_centers_[:,0],km.cluster_centers_[:,1],color='purple',marker='*',label='centroid')\n",
    "plt.xlabel('Age')\n",
    "plt.ylabel('Income ($)')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style='color:purple'>Preprocessing using min max scaler</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "scaler = MinMaxScaler()\n",
    "\n",
    "scaler.fit(df[['Income($)']])\n",
    "df['Income($)'] = scaler.transform(df[['Income($)']])\n",
    "\n",
    "scaler.fit(df[['Age']])\n",
    "df['Age'] = scaler.transform(df[['Age']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "      <th>Income($)</th>\n",
       "      <th>cluster</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Rob</td>\n",
       "      <td>0.058824</td>\n",
       "      <td>0.213675</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Michael</td>\n",
       "      <td>0.176471</td>\n",
       "      <td>0.384615</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mohan</td>\n",
       "      <td>0.176471</td>\n",
       "      <td>0.136752</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ismail</td>\n",
       "      <td>0.117647</td>\n",
       "      <td>0.128205</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Kory</td>\n",
       "      <td>0.941176</td>\n",
       "      <td>0.897436</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name       Age  Income($)  cluster\n",
       "0      Rob  0.058824   0.213675        2\n",
       "1  Michael  0.176471   0.384615        2\n",
       "2    Mohan  0.176471   0.136752        0\n",
       "3   Ismail  0.117647   0.128205        0\n",
       "4     Kory  0.941176   0.897436        1"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x159c78f2358>"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEhJJREFUeJzt3W+MXFd5x/HvU8eRFkFZhBeE197arYypJZMaliSCqA0g\najtvbKxITYKIiJAsqwT1lRWnL+AFLxwUVaIoCZYVRShvsFCxjGkNbtUIUjW4tV0ncZzIaGtK7DVS\nEsBUgpUSJ09fzLiMl13vXe+dP/fM9yNZ3nvnaOY5svXbM+eee25kJpKksvxBvwuQJNXPcJekAhnu\nklQgw12SCmS4S1KBDHdJKpDhLkkFMtwlqUCGuyQV6IZ+ffCKFStyzZo1/fp4SWqkkydPvpaZYwu1\n61u4r1mzhhMnTvTr4yWpkSLiZ1XaOS0jSQUy3CWpQIa7JBXIcJekAhnuklQgw12SCmS4S1KBFgz3\niHgiIl6JiBfmeT0i4usRMRURz0fEh+ovU5K0GFVuYvom8Ajw5DyvbwXWtf/cAnyj/bekBjh0apqH\nj57l4qUZVo6OsHvzerZvGu93WVqiBUfumfk08MtrNNkGPJktx4DRiHhfXQVK6p5Dp6Z58OBppi/N\nkMD0pRkePHiaQ6em+12alqiOOfdx4HzH8YX2OUkD7uGjZ5l5482rzs288SYPHz3bp4pUl57uLRMR\nO4GdABMTE738aElzuHhpZlHnm8KppnpG7tPA6o7jVe1zvycz92fmZGZOjo0tuKmZpC5bOTqyqPNN\n4FRTSx3hfhi4t71q5lbg15n58xreV1KX7d68npHly646N7J8Gbs3r+9TRUvnVFPLgtMyEfEt4HZg\nRURcAL4MLAfIzH3AEeAOYAr4LXBft4qVVK8rUxUlTWGUOtW0WAuGe2bevcDrCXyhtook9dT2TeON\nDvPZVo6OMD1HkDd5qul6eIeqpKKUONV0Pfr2JCZJ6oYSp5quh+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lYDr3PKe9QlaQCNWVaRpK0CIa7JBXIcJek\nAhnuklQgw12SCmS4S1KBDHdJKpDhLkkF+j/wcNFP+6aVeQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x159c751a470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(df.Age,df['Income($)'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2])"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "km = KMeans(n_clusters=3)\n",
    "y_predicted = km.fit_predict(df[['Age','Income($)']])\n",
    "y_predicted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "      <th>Income($)</th>\n",
       "      <th>cluster</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Rob</td>\n",
       "      <td>0.058824</td>\n",
       "      <td>0.213675</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Michael</td>\n",
       "      <td>0.176471</td>\n",
       "      <td>0.384615</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mohan</td>\n",
       "      <td>0.176471</td>\n",
       "      <td>0.136752</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ismail</td>\n",
       "      <td>0.117647</td>\n",
       "      <td>0.128205</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Kory</td>\n",
       "      <td>0.941176</td>\n",
       "      <td>0.897436</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name       Age  Income($)  cluster\n",
       "0      Rob  0.058824   0.213675        0\n",
       "1  Michael  0.176471   0.384615        0\n",
       "2    Mohan  0.176471   0.136752        0\n",
       "3   Ismail  0.117647   0.128205        0\n",
       "4     Kory  0.941176   0.897436        1"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['cluster']=y_predicted\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.1372549 ,  0.11633428],\n",
       "       [ 0.72268908,  0.8974359 ],\n",
       "       [ 0.85294118,  0.2022792 ]])"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "km.cluster_centers_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x159c7982f60>"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQIC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x2u+8sorXlJS4jt37nR39/r6ep86dap/+eWXvm/fPp88ebL/+c9/dnf3UaNG\nubv76tWr/YILLvD29nbftWuXl5aW+qpVq/o9Lq1QFYkGAlyhWpBW37CabWu2ceDrAwA8d+NzrP3p\nWiZdNomrHr+q36/78ssvc80113DCCScAMHbsWF588UW2bv3bgtwvvviCL7/8EoBLLrmEo446iqOO\nOooTTzyRv/71r92+7pw5c5gwYQIAr7/+OldccQWjRo0C4Morr+S1117j7LPP7ui/bt06rr/+eoYN\nG8Ypp5zCeeed1+8xicjQE9pwr7q3iv96+7/4vOFzUu0pioqLGBMbQ9V9VYG/VyqV4s033+Too48+\n7LlstwU+GOQiIrkQ2jn3saePpereKlL7UxSPKia1P0XlPZWMPW3sgF73vPPOY9WqVezZsweAzz77\njIsuuoiHHnqoo093+653dswxx7Bv374en58/fz7PPfccra2tfPXVVzz77LPMnz//kD4LFizgySef\n5MCBA+zevbvjtn2SZ1ryLyER2nAH2PLUFopHFVN5TyXFo4rZsmrLgF9zypQp1NTUcO655zJjxgxu\nv/12HnzwQerr65k+fTqTJ09m2bJlR3yN448/nu9+97tMnTqVO+6447DnZ86cyU033cScOXP4zne+\nw09+8pNDpmQArrjiCiZOnMjkyZO58cYbmTt37oDHJgOkJf8SIuaZmz7nWkVFhdfX1x/S9t5773Hm\nmWdm/Rq7NuyitLyU0SeN5su/fskXH33BKRWnBF1qJPT1dyvdiMfTgd5VLJa+WkUkB8xso7tX9NYv\ntHPuAONm/21zytEnjWb0SaPzWI1Enpb8S4iEelpGJKe05F9CpODCPV/TRFGm32lAtORfQqSgwv3o\no49mz549CqMAuTt79uzp9jJO6SMt+ZcQKagTqvv376e5uZm2tuC2EpD0f5rjx4+nuLg436WIyACF\n8oRqcXFxxypOERHpv4KalhERkWAo3EVEIkjhLiISQQp3EZEIUriLiESQwl1EJIIU7iIiEaRwFxGJ\nIIW7iEgEKdxFRCJI4S4iEkEKdxGRCFK4i4hEkMJdRCSCFO4iIhGUVbib2UIz22Z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at 0x159c782dd30>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df1 = df[df.cluster==0]\n",
    "df2 = df[df.cluster==1]\n",
    "df3 = df[df.cluster==2]\n",
    "plt.scatter(df1.Age,df1['Income($)'],color='green')\n",
    "plt.scatter(df2.Age,df2['Income($)'],color='red')\n",
    "plt.scatter(df3.Age,df3['Income($)'],color='black')\n",
    "plt.scatter(km.cluster_centers_[:,0],km.cluster_centers_[:,1],color='purple',marker='*',label='centroid')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style='color:purple'>Elbow Plot</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "sse = []\n",
    "k_rng = range(1,10)\n",
    "for k in k_rng:\n",
    "    km = KMeans(n_clusters=k)\n",
    "    km.fit(df[['Age','Income($)']])\n",
    "    sse.append(km.inertia_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x159c7a34978>]"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEKCAYAAAARnO4WAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XuUXXV99/H391zmnpkkk8kJJCE3cpkx3FMUgSjJTIpC\nEbG1ttqbPgt9SvtgqbVitVRXaelFl62KjxQttbW4VOARqygJdwSFBIGEJMQQEpKQy+Q+9+v3+ePs\nSSbJZOZMMnv2OWd/XmvtdS5zztkfo35/Z//Ob3+3uTsiIlL8ElEHEBGR8aGCLyISEyr4IiIxoYIv\nIhITKvgiIjGhgi8iEhMq+CIiMaGCLyISEyr4IiIxkY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twOXBdMFf+HWCZmf1XtJGOCb4d4u57gQfI\nzrdGbQewY9AR2vfJDgD54l3AC+6+J+oggUbgdXdvdvce4H7g7RFnAsDdv+Hul7j7UuAgsCmsfang\nhyD4cfSsMIvhAAAB1ElEQVQbwAZ3/2LUeQaYWZ2ZTQzulwNNwMZoU4G73+ruM9x9NtlpgEfdPfJv\nXwBmVhn88E4wZbKC7GF4pNx9N7DdzBYGTy0HIl0UcILfIU+mcwJvAG8zs4rg/5/Lyf62Fjkzmxrc\nnkN2/v6/w9pXqP3wx4OZ3Qu8E5hiZjuA29z9G9Gm4nLg94C1wXw5wKeD6wNE6SzgP4LVEwngu+6e\nV0sg81AGeCBbI0gB/+3uP4k20lF/Cnw7mD7ZAvxRxHmAowNjE/DRqLMMcPdfmNn3gReAXuCX5M9Z\nt/eZWS3QA9wU5o/vBb8sU0REcqMpHRGRmFDBFxGJCRV8EZGYUMEXEYkJFXwRkZhQwRcZhpm1Drr/\nbjPbZGazoswkcroKfh2+yHgws+XAvwK/nkfNwERGRQVfZARB75x/A97t7q9FnUfkdOnEK5FhmFkP\n0AK8091fjjqPyJnQHL7I8HqAZ4CPRB1E5Eyp4IsMrx94P9lW0p+OOozImdAcvsgI3L3dzK4BnjKz\nPXnQnE/ktKjgi+TA3Q+Y2dXAk2bW7O4PRp1JZLT0o62ISExoDl9EJCZU8EVEYkIFX0QkJlTwRURi\nQgVfRCQmVPBFRGJCBV9EJCZU8EVEYuL/A3oVJDVdfnaoAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x159c794b828>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.xlabel('K')\n",
    "plt.ylabel('Sum of squared error')\n",
    "plt.plot(k_rng,sse)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4 style='color:purple'>Exercise</h4>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src='iris.png' width=200 height=200>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Use iris flower dataset from sklearn library and try to form clusters of flowers using petal width and length features. Drop other two features for simplicity.\n",
    "2. Figure out if any preprocessing such as scaling would help here\n",
    "3. Draw elbow plot and from that figure out optimal value of k"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
